package src.main.kotlin.day08

/**
 * 延迟初始化
 *  lateinit: 使用此关键字相当于做了一个约定：在用它之前负责初始化
 *  只要无法确认lateinit 变量是否完成初始化，可以执行isInitialized检查
 *
 */
fun main() {

    val initTest = initTest()
    initTest.ready()
    //如果不先初始化会报异常
    //kotlin.UninitializedPropertyAccessException:
    // lateinit property equipment has not been initialized
    initTest.battle()

}

class initTest(){
    lateinit var equipment:String

    fun ready(){
        equipment = "sharp knife"
    }

    fun battle() {
//        println(equipment)
        if (::equipment.isInitialized) println(equipment)
    }

}